package com.mrstage.ndkplayer;

public class NDKPlayer {


    // Used to load the 'native-lib' library on application startup.
    static {
        System.loadLibrary("native-lib");
    }

    private OnPreparedListener onPreparedListener;
    private String dataSource;

    public String getDataSource() {
        return dataSource;
    }

    public void setDataSource(String dataSource) {
        this.dataSource = dataSource;
    }


    /**
     * 播放前准备工作
     */
    public void prepare() {
        prepareNative(dataSource);
    }



    /**
     * 开始播放
     */
    public void start() {
        startNative();
    }



    /**
     * 停止播放
     */

    public void stop() {
        stopNative();
    }


    /**
     * 释放资源
     */

    public void release() {
        releaseNative();
    }


    public void onPrepare() {
        if (onPreparedListener != null) {
            onPreparedListener.onPrepare();
        }
    }

    public void setOnPreparedListener(OnPreparedListener listener) {
        this.onPreparedListener = listener;
    }


    public interface OnPreparedListener {
        /**
         * 给native反射调用
         */

        void onPrepare();
    }

    private native void prepareNative(String dataSource);
    private native void startNative();
    private native void stopNative();
    private native void releaseNative();
}
